package org.personae.web;

import java.util.Map;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.personae.orp.chantres.*;
import org.personae.orp.chantres.util.HibernateUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/personne")
public class PersonneController {

	/**
	 * @param args
	 */
	  @RequestMapping(method = RequestMethod.GET)
      public String get(Map model) {
		  Personne p=new Personne();
		  
		  p.setObjet(new Objet());
		  model.put("personne", p);
		return "personne";	
		
		
	}
	  @RequestMapping(value="delete", method = RequestMethod.GET)
      public String delete(Map model, @RequestParam int id) {
			 Session session = HibernateUtil.currentSession(); 
			  Transaction tx = session.beginTransaction(); 
			Personne p=(Personne) session.get(Personne.class, id);
			
		  session.delete(p);
		  tx.commit();
		return "succ";			
		
	}
	  @RequestMapping(method = RequestMethod.POST)
	  public String post(Map model, Personne p){

		 Session session = HibernateUtil.currentSession(); 
	   	  Transaction tx = session.beginTransaction(); 
Objet o=new Objet();

p.setObjet(o);
	   	session.save(p);
	   	tx.commit();
		 // model.put("personne", p);
		return "personne";
		  
		  
	  }
}
